package com.elinkway.infinitemovies.http.requesttask;

import android.content.Context;
import android.os.AsyncTask;

import com.elinkway.infinitemovies.config.SettingManage;
import com.elinkway.infinitemovies.http.api.MoviesHttpApi;
import com.elinkway.infinitemovies.ui.activity.LoginActivity;
import com.elinkway.infinitemovies.ui.fragment.CopyrightFragment;
import com.elinkway.infinitemovies.utils.ImageUploadUtil;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by zhaopeipei on 2016/5/1.
 */
public class UploadImageTask extends AsyncTask<Void, Void, Void> {

    private String fileName;
    private File file;
    private Context mContext;
    private CopyrightFragment mCopyrightFragment;
    private String mImageUrl;

    public UploadImageTask(Context context, CopyrightFragment copyrightFragment,
                           String url) {
        super();
        this.mContext = context;
        mCopyrightFragment = copyrightFragment;
        mImageUrl = url;
    }

    @Override
    protected Void doInBackground(Void... params) {
        Map<String, String> param = new HashMap<>();
        param.put("suffix", "png");
        param.put("uid", mContext.getSharedPreferences(SettingManage.LOGIN_INFO, Context.MODE_PRIVATE)
                .getString(LoginActivity.UID, ""));
        ImageUploadUtil.getInstance().setOnUploadProcessListener(mCopyrightFragment);
        ImageUploadUtil.getInstance().uploadFile(mImageUrl,
                mContext.getSharedPreferences(SettingManage.LOGIN_INFO,
                        Context.MODE_PRIVATE).getString(LoginActivity.TOKEN, ""),
                MoviesHttpApi.getStaticHead() + "kuaikan/apiimgupload_json.so?type=copyright&apiversion=2", param);
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        return;
    }
}
